
class Renderer < Thing
  def initialize
    
  end

  def creator e

  end

  def recieve e
    Pattern::Property.properties(self.class, :attribute).each { |attr, definition|
      if data = e.params[(form_id attr)]
        self.send(attr.to_s+'=', data)
      end
    }
    super
  end

end


class ShortTextRenderer < Renderer
  attribute :length

  def length= l
    @length = l.to_i
  end

  def creator e
    "Zkrátit na délku: "+
      InputText.new(
        :name => (form_id :length),
        :value => length
      ).to_s
  end

  def render text
    text[0, length]
  end
end

class AnchorRenderer < Renderer
  attribute :caption

  def creator e
    "text odkazu: "+
      InputText.new(
        :name => (form_id :caption),
        :value => caption
      ).to_s
  end
end

class TitleRenderer < Renderer
  attribute :level

  def level= l
    @level = l.to_i
  end

  def creator e
    s = Select.new(:name => (form_id :level))
    s.options = (1..6).map { |n| [n, 'H'+n.to_s] }
    s.value = level
    s
  end

  def render data
    Element.new("h"+level.to_s, data)
  end

end